package com.xulinhao.edu.controller.front;/**
 * @author xulinhao
 * @create 2021-09-13 22:15
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xulinhao.commonutils.R;
import com.xulinhao.edu.entity.Course;
import com.xulinhao.edu.entity.Teacher;
import com.xulinhao.edu.service.CourseService;
import com.xulinhao.edu.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author xlh
 * @packagename: com.xulinhao.edu.controller.front
 * @classname: TeacherFrontController
 * @Description:
 * @Date 2021/9/13
 */
@RestController
@CrossOrigin
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    //分页查询讲师的方法
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<Teacher> teacherPage = new Page<>(page, limit);
        Map<String, Object> map = teacherService.getTeacherFrontList(teacherPage);
        //返回分页所有数据
        return R.ok().data(map);
    }

    //讲师详情的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        //根据讲师id查询讲师基本信息
        Teacher teacher = teacherService.getById(teacherId);
        //根据讲师id查询所讲课程
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", teacherId);
        List<Course> list = courseService.list(wrapper);
        return R.ok().data("teacher", teacher).data("courseList", list);
    }

}
